﻿using System.ComponentModel.DataAnnotations;

namespace Day.Data;

public class DayModel
{
    [Key]
    public int Key { get; set; }
    public string DayName { get; set; }
    public string DayTime { get; set; }
    public string DayIntroduce { get; set; } = "";
    public string DayImage { get; set; } = "";

    public bool IsNull()
        => string.IsNullOrEmpty(DayName) || string.IsNullOrEmpty(DayTime);
}

public static class DayStatic
{
    public static DateTime StringToDateTime(this string s)
        => DateTime.Parse(s);

    /// <summary>
    /// 04/18/2008
    /// </summary>
    /// <param name="time"></param>
    /// <returns></returns>
    public static string DateTimeToString(this DateTime time) => time.ToString("d");

    public static string DateTimeOffsetToString(this DateTimeOffset offset)
    {
        return offset.DateTime.DateTimeToString();
    }

    public static string ImageToString(this byte[] data) => Convert.ToBase64String(data);

    public static byte[] StringToImage(this string s) => Convert.FromBase64String(s);

    public static DayModel DefaultDay => new()
    {
        DayName = "软件写成",
        DayTime = "10/28/2023",
        DayIntroduce = "没错，这个软件是我用一个小时写成的"
    };
}